package com.lvyq.myplayer.adapter


import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.model.index.IndexDailyBean
import com.lvyq.myplayer.model.index.IndexPickPlayLstBeans
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import org.jetbrains.anko.find


/**
 * 文件描述：IndexAdapter
 * 作者：lvyq
 * 创建时间：2025-03-24
 * 修改时间：2025-03-24
 */
class IndexGeDanAdapter(var context: Context?,var datas:List<IndexPickPlayLstBeans>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {


    // 定义点击事件接口
    interface OnItemClickListener {
        fun onItemClick(data: IndexPickPlayLstBeans, position: Int)
    }

    private var onItemClickListener: OnItemClickListener? = null

    fun setOnItemClickListener(listener: OnItemClickListener) {
        this.onItemClickListener = listener
    }
/*
    companion object{
        val Banner_TYPE= 0 //头部-
        val GeDan_TYPE = 1
    }

    *//**
     * 根据position判断view类型
     *//*
    override fun getItemViewType(position: Int): Int {
        if (position==0){
            return Banner_TYPE
        }else if (position==1){
            return GeDan_TYPE
        }else{
            return Banner_TYPE
        }

    }*/

    fun setData( datas: IndexDailyBean){
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = View.inflate(context, R.layout.item_index_gedan,null)
        return indexGeDanHolder(view)
    }

    override fun getItemCount(): Int {
            return  datas.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
         var data = datas.get(position)
        (holder as indexGeDanHolder).setData(data)
        // 绑定点击事件
        holder.itemView.setOnClickListener {
            onItemClickListener?.onItemClick(data, position)
        }
    }

    /**
     * 推荐歌单
     */
    inner  class  indexGeDanHolder(item:View): RecyclerView.ViewHolder(item){

        val geDanImg:ImageView
        val playNum:TextView
        val gedanTitle:TextView
        init {
            geDanImg=item.find(R.id.geDanImg)
            playNum=item.findViewById(R.id.playNum)
            gedanTitle=item.findViewById(R.id.gedanTitle)
        }
        fun setData(data: IndexPickPlayLstBeans) {
            Picasso.with(context).load(data.img).transform(RoundedCornersTransformation(30,0)).into(geDanImg)
            gedanTitle.text=data.title
        }
    }
}